package study.stream.reduce;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONString;
import cn.hutool.json.ObjectMapper;
import org.apache.ibatis.builder.annotation.MapperAnnotationBuilder;
import org.springframework.util.ObjectUtils;
import study.User;
import study.Utils;
import study.utils.JsonUtils;

import java.util.List;
import java.util.Optional;

/**
 * @Author 刘伟涛
 * @Date 2024/1/17 9:16
 **/
public class ReduceDemo02 {
    public static void main(String[] args) {
        List<User> anyUserList = Utils.getAnyUserList(12);
        anyUserList.get(0).setAge(5);
        System.out.println(JsonUtils.objectToJson(anyUserList));
        int sum = anyUserList.stream().mapToInt(user-> Optional.ofNullable(user.getAge()).orElse(0)).sum();
        System.out.println(sum);
    }
}
